const App = {
  mixins: [Query],//配置文件，路径/utils/mixins.js
  data() {
    return {
      // treeData: [],
      category: [],
      village: [],
      page: {
        activeName: '',
        value1: '',
        //value2:'',
        PageNumber: 1, //页码
        RowAmount: 10,
        Condition: window.btoa(unescape(encodeURIComponent("%%,%%"))),
        ExtensionCondition: window.btoa(unescape(encodeURIComponent("")))
        //Condition:"",
      },
    }
  },
  mounted() {

  },
  methods: {
    getCategorys(data, arr) {
      data.forEach((item) => {
        arr.push(item.category_id);
        if (item.children && item.children.length > 0) {
          this.getCategorys(item.children, arr);
        }
      });
    },

    handleClick() {
      if (this.page.activeName == 'first') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('处理')")));
      } else if (this.page.activeName == 'second') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('已处理')")));
      } else if (this.page.activeName == 'three') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('拒绝')")));
      } else if (this.page.activeName == 'four') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('处理','已处理','拒绝')")));
      } else {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("")));
      }
      this.postgetList(this.page);
    },
    complaintsAdd() {
      window.location.href = "./add.html?action=Add";
    },


    check() {
      this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%" + ",%%")));
      this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("")));
      this.postgetList(this.page);
    },
    //树的点击筛选事件
    handleNodeClick(data, node) {

      let arr = [];
      if (data.children) {
        this.getCategorys(data.children, arr);
      }
      let strwhereCategory_ids = "";
      [data.category_id, ...arr].forEach((item) => {
        if (strwhereCategory_ids) {
          strwhereCategory_ids += "\r\nOR complaints.category_id='" + item + "'";
        } else {
          strwhereCategory_ids = "\r\complaints.category_id='" + item + "'";
        }
      });
      if (strwhereCategory_ids) {
        strwhereCategory_ids = "AND (" + strwhereCategory_ids + ")";
      }



      // let strwhere = strwhereCategory_ids;

      this.page.Condition = window.btoa(unescape(encodeURIComponent("%" + this.page.value1 + "%,%%")));

      if (this.page.activeName == 'first') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('处理')" + strwhereCategory_ids)));
      } else if (this.page.activeName == 'second') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('已处理')" + strwhereCategory_ids)));
      } else if (this.page.activeName == 'three') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('拒绝')" + strwhereCategory_ids)));
      } else if (this.page.activeName == 'four') {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent("AND complaints.status in ('处理','已处理','拒绝')" + strwhereCategory_ids)));
      } else {
        this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent(strwhereCategory_ids)));
      }

      // this.page.ExtensionCondition = window.btoa(unescape(encodeURIComponent()));
      this.postgetList(this.page);
    },
    allocationAdd(row, allocationType) {

      //allocationType:分配类型,0为分配,1为再分配
      let { primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
      let tablekey = row[primary_key];

      //complaints_processing_records where complaint_id ='CP0000000000013' and action_type  not in ('已处理','拒绝')
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryByTableName`,
        type: "POST",
        data: {
          Data: 'complaints_processing_records',
          Condition: "Row_Status='0' and action_type  not in ('已处理','拒绝')  and complaint_id ='" + tablekey + "'",
        },
        success: (res) => {
          if (res.length > 0) {
            this.$message.error("此事件已有跟进人,禁止重复分配!");
            return;
          }
          else {
            window.location.href = "./allocation.html?action=Modify&nodeKey=" + row[primary_key] + "&bQuery=false&allocationType=" + allocationType;
          }

        },
        complete: (XMLHttpRequest) => {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json",
      });





    },
    allocationQuery(row) {

      let { primary_key } = JSON.parse(document.getElementById("table").getAttribute("data-options"));
      window.location.href = "./allocationQuery.html?action=Modify&nodeKey=" + row[primary_key] + "&bQuery=true";

    },
  },
};

const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
